<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">

        <ui:define name="title">
            <h:outputText value="#{bundle.ListFuncaoTitle}"></h:outputText>
        </ui:define>

        <ui:define name="body">

            <h:panelGroup id="messagePanel" layout="block">
                <p:growl />
            </h:panelGroup>

            <h:form id="formFuncaoList">

                <h:panelGroup>

                    <p:dataTable id="tableFuncao" value="#{funcaoController.items}" var="item"
                                 emptyMessage="#{bundle.ListFuncaoEmpty}">

                        <f:facet name="header">#{bundle.ListFuncaoTitle}</f:facet>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListFuncaoTitle_descricao}"/>
                            </f:facet>
                            <h:outputText value="#{item.descricao}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <p:commandButton actionListener="#{funcaoController.prepareCreate}" 
                                                 value="#{bundle.ListFuncaoCreateLink}"
                                                 update=":formFuncaoCreate:pgFuncaoCreate" 
                                                 oncomplete="dialogFuncaoCreate.show()"/>
                            </f:facet>
                            <p:commandButton actionListener="#{funcaoController.prepareEdit}" 
                                             value="#{bundle.ListFuncaoEditLink}"
                                             update=":formFuncaoEdit:pgFuncaoEdit" 
                                             oncomplete="dialogFuncaoEdit.show()" />
                            <p:commandButton actionListener="#{funcaoController.destroy}" 
                                             value="#{bundle.ListFuncaoDestroyLink}" ajax="false"/>

                        </p:column>

                    </p:dataTable>
                </h:panelGroup>

            </h:form>

            <h:form id="formFuncaoCreate">

                <p:dialog header="#{bundle.CreateFuncaoTitle}" widgetVar="dialogFuncaoCreate" 
                          resizable="false" modal="true" showEffect="slide">
                    <p:panelGrid id="pgFuncaoCreate" columns="2">

                        <h:outputLabel value="#{bundle.CreateFuncaoLabel_descricao}" for="descricao" />
                        <p:inputText id="descricao" value="#{funcaoController.selected.descricao}" 
                                     title="#{bundle.CreateFuncaoTitle_descricao}" required="true"
                                     requiredMessage="#{bundle.CreateFuncaoRequiredMessage_descricao}"/>

                        <p:commandButton actionListener="#{funcaoController.create}" 
                                         update=":formFuncaoList:tableFuncao" 
                                         value="#{bundle.CreateFuncaoSaveLink}" 
                                         oncomplete="dialogFuncaoCreate.hide()" ajax="false" />
                        <p:commandButton value="Limpar" type="reset" 
                                         update=":formFuncaoCreate:pgFuncaoCreate" ajax="false"/>
                    </p:panelGrid>
                </p:dialog>

            </h:form>

            <h:form id="formFuncaoEdit">

                <p:dialog header="#{bundle.EditFuncaoTitle}" widgetVar="dialogFuncaoEdit" resizable="false" modal="true" showEffect="slide">
                    <p:panelGrid id="pgFuncaoEdit" columns="2">

                        <h:outputLabel value="#{bundle.EditFuncaoLabel_descricao}" for="descricao" />
                        <p:inputText id="descricao" value="#{funcaoController.selected.descricao}" 
                                     title="#{bundle.EditFuncaoTitle_descricao}" required="true"
                                     requiredMessage="#{bundle.EditFuncaoRequiredMessage_descricao}"/>

                        <p:commandButton actionListener="#{funcaoController.update}" update=":formFuncaoList:tableFuncao" 
                                         value="#{bundle.EditFuncaoSaveLink}" oncomplete="dialogFuncaoEdit.hide()" ajax="false" />
                        <p:commandButton value="Cancelar" oncomplete="dialogFuncaoEdit.hide()" ajax="false"/>
                    </p:panelGrid>
                </p:dialog>

            </h:form>

        </ui:define>
    </ui:composition>

</html>
